package com.set.mobileapp.util;

import java.io.InputStream;
import java.io.OutputStream;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.view.View;

public class MobileAppUtils {
	public static final String DB_PATH = "/data/data/com.set.mobileapp/databases/";
	public static final String DB_NAME = "spi.db";
	
	public static final String KPI_PATH = "";
	
	
	public static void closeIs(InputStream is) {
		if (is != null) {
			try {
				is.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}

	public static void closeOs(OutputStream os) {
		if (os != null) {
			try {
				os.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}

	public static void closeDB(SQLiteDatabase db) {
		if (db != null) {
			db.close();
		}
	}

	public static void closeCursor(Cursor c) {
		if (c != null) {
			c.close();
		}
	}
	
	
	public static void showProgress(final boolean show, final View basicView,
			final View statusBarView,Context ctx) {
		// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
		// for very easy animations. If available, use these APIs to fade-in
		// the progress spinner.
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
			int shortAnimTime = ctx.getResources().getInteger(
					android.R.integer.config_shortAnimTime);

			statusBarView.setVisibility(View.VISIBLE);
			statusBarView.animate().setDuration(shortAnimTime)
					.alpha(show ? 1 : 0)
					.setListener(new AnimatorListenerAdapter() {
						@Override
						public void onAnimationEnd(Animator animation) {
							statusBarView.setVisibility(show ? View.VISIBLE
									: View.GONE);
						}
					});

			basicView.setVisibility(View.VISIBLE);
			basicView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
					.setListener(new AnimatorListenerAdapter() {
						@Override
						public void onAnimationEnd(Animator animation) {
							basicView.setVisibility(show ? View.GONE
									: View.VISIBLE);
						}
					});
		} else {
			// The ViewPropertyAnimator APIs are not available, so simply show
			// and hide the relevant UI components.
			statusBarView.setVisibility(show ? View.VISIBLE : View.GONE);
			basicView.setVisibility(show ? View.GONE : View.VISIBLE);
		}
	}


}
